﻿//
// Created by LiuYou on 2021/4/19.
//

#include <iostream>


// #include <algorithm>
// std::cout << std::max({1, 2, 3, 1999, 34141}) << std::endl;


class _Iter_less_iter {
public:
    template<typename _Iterator1, typename _Iterator2>
    bool operator()(_Iterator1 __it1, _Iterator2 __it2) const {
        return *__it1 < *__it2;
    }
};


template<typename _ForwardIterator, typename _Compare>
_ForwardIterator
__max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp);

template<typename _ForwardIterator>
inline _ForwardIterator
max_element(_ForwardIterator __first, _ForwardIterator __last) {
    return __max_element(__first, __last, __iter_less_iter());
}


_Iter_less_iter __iter_less_iter();

template<typename _Tp>
inline _Tp
max(std::initializer_list<_Tp> __l) {
    return *max_element(__l.begin(), __l.end());
}


/**
 * @brief 在一堆数据中找到最大的值
 *
 * 泛型编程(GP)真的不习惯。头疼！
 *
 *
 * @return
 */
int main() {
    std::cout << max({100, 43214, 8, 41, 18}) << std::endl;


    return 0;
}

template<typename _ForwardIterator, typename _Compare>
_ForwardIterator __max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) {
//    return nullptr;
    if (__first == __last) {
        return __first;
    }
    _ForwardIterator __result = __first;
    while (++__first != __last) {
        if (__comp(__result, __first)) {
            __result = __first;
        }
    }
    return __result;
}


_Iter_less_iter __iter_less_iter() {
//    return nullptr;
    return _Iter_less_iter();
}
